/*
 * @Author: Du.M
 * @Date: 2021-08-17 15:59:45
 * @LastEditTime: 2021-08-23 10:03:31
 * @FilePath: \express_basics\service\mainServer.js
 */
const { querySql } = require("../utils")
const moment = require('moment')

const getBackground = (req,res,next) =>{
    const sql = `select * from background; `
    querySql(sql).then( result =>{
        const newArr = []
        const len = result.length
        for(let index in new Array(5).fill('0')){
            const num = Math.floor(Math.random() * (len - index))
            newArr.push(result[num])
            result.splice(num,1)
        }
        res.status(200).json(newArr)
    })

}
const getLottery = (req,res,next) =>{
    const time = moment(new Date()).format('YYYY-MM-DD');
    const sql = `select * from nums where date = '${time}'`
    querySql(sql).then( result =>{
        res.status(200).json(result)
    })

}
module.exports = {
    getBackground,
    getLottery,
}